package com.kele.mylock;

import java.util.concurrent.TimeUnit;

/**
 * @author kele
 * @date 2021/10/14 15:43
 * @description
 */
public class TestMyLock {
    public static void main(String[] args) {
        MySpinLockTest lock=new MySpinLockTest();

        new Thread(()->{
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.myUnLock();
            }
        },"A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {

                lock.myUnLock();
            }
        },"B").start();

    }
}
